home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / com32 / lib / strndup.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-11-10  |  224 b   |  18 lines

  1. /*
  2.  * strndup.c
  3.  */
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. char *strndup(const char *s, size_t n)
  9. {
  10.     int l = n > strlen(s) ? strlen(s)+1 : n+1;
  11.     char *d = malloc(l);
  12.  
  13.     if (d)
  14.         memcpy(d, s, l);
  15.     d[n] = '\0';
  16.     return d;
  17. }
  18.